<?php

/*
 * 第三方服务 邮件查询这类工作
 */

/**
 * Description of third_party_services
 *
 * @author Administrator
 */
class Third_party_services extends CLI_Controller{
    private $third_party_list;//可用的第三方服务 列表 array
    public function __construct() {
        parent::__construct();
        $this->load->library('socket_server');
        $this->load->config('third_party',true);
        $this->third_party_list = array(
            'post' //快递
        );
    }
    /*
     * 创建一个服务
     */
    public function service()
    {
        CLI_FUN::cli_echo("第三方查询接口开始执行 \n");
        $this->socket_server->set_port($this->config->item('third_party_service_port','third_party'));
        $this->socket_server->set_ip($this->config->item('third_party_service_ip','third_party'));
        try{
            $this->socket_server->init();
            do{
                $this->socket_server->accept();
                $data = $this->socket_server->read();
                if(is_string($data))
                {
                    $third_party_data = json_decode($data);
                    if(!isset($third_party_data->type) || !in_array($third_party_data->type, $this->third_party_list))
                    {
                        
                    }
                }
                else
                {
                    $msg = '信息错误';
                }
                
                $this->socket_server->write($this->msg($data));
                $close = $this->socket_server->close();
                if($close == false)
                {
                        break;
                }
            }while (true);
            CLI_FUN::cli_echo("第三方查询接口停止");
        }catch (Exception $e) {
            CLI_FUN::cli_echo($e->getMessage());
        }
    }
}